$.ajax({
  type: "GET",
    url: "/api/search/index",
    success: function (res) {
        console.log(res.data);
        var htmlStr = template('tpl-history', res.data)
        var htmlStr2 = template('tpl-hot', res.data)
        var htmlStr3 = template('tpl-input', res.data)

        $('#history').html(htmlStr)
        $('#hot').html(htmlStr2)
      $('.search-header').html(htmlStr3)


      var timer = null; // 1. 防抖动的 timer
      function debounceSearch(keywords) {
        // 2. 定义防抖的函数
        timer = setTimeout(function () {
          // 发起 JSONP 请求
          getSuggestList(keywords);
        }, 100);
      }
      $(".keywrod").on("keyup", function () {
         clearTimeout(timer);
        $(".no-search").hide();
        $(".lx").show();
        var str = $(".keywrod").val();
         debounceSearch(str);
        if (str == "") {
          $(".no-search").show();
          $(".lx").hide();
        }
      });
     function getSuggestList(keywords) {
        $.ajax({
          type: "GET",
          url: "/api/search/helper?keyword=" + keywords,
          success: function (res) {
            console.log(res);
            var htmlStr = template("tpl-lx", res);
            console.log(htmlStr);
            $(".lx").html(htmlStr);
            $("#red").html(keywords);
          },
        });
      }
      $(".search-header .del").click(function () {
        $(".keywrod").val('');
         $(".no-search").show();
         $(".lx").hide();
      })
     
  }
});
$(document).on('keyup', function (e) {
  console.log(66);
  if (e.keyCode == 13) {
    console.log(12);
    var str = $(".keywrod").val();
    location.href = './category520.html?search=' + str
  }
})
